package com.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import javax.servlet.ServletException;

public class DB {

    private static Connection c;

    public static void connect() throws ServletException {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            c = DriverManager.getConnection("jdbc:mysql://10.8.102.36/picseek", "root", "");
        } catch (Exception e) {
            throw new ServletException(e);
        }
    }

    public static ResultSet fetch(String sql) throws ServletException {
        try {
            if (c == null) {
                connect();
            }
            return c.createStatement().executeQuery(sql);
        } catch (Exception e) {
            throw new ServletException(e);
        }
    }

    public static void save(String sql) throws ServletException {
        try {
            if (c == null) {
                connect();
            }
            c.createStatement().executeUpdate(sql);
        } catch (Exception e) {
            throw new ServletException(e);
        }
    }
    
    
}
